<template>
  <div class="v-navigation">
    <div class="v-menu-wrapper" v-ripple @click="handleTriggerMenu">
      <v-icon icon="custom-icon-caidan1" width="2em" height="2em" />
    </div>
    <div class="wrapper" :ref="getNavicationVdom"></div>
  </div>
</template>

<script lang="ts">
import { onMounted, defineComponent, inject, ref } from "vue";
import { useNavigation } from "@/use/UseNavigation.ts";
import { sideWidth } from '@/config/layout';
import Icon from '@/components/Icon.vue';

export default defineComponent({
  components: {
    'v-icon': Icon
  },
  props: {
    // 是否只保持一个子菜单的展开
    uniqueOpened: {
      type: Boolean,
      default: false,
    },
  },
  setup(props, context) {
    const $bg = inject('$bg');
    const $color = inject('$color');
    const use = useNavigation(props, context, { $bg, $color });
    const _sideWidth = ref(sideWidth);
    onMounted(() => {
      use.createNav(use.navicationDom.value as HTMLElement, use.navication, false, 0, 0);
      setTimeout(() => {
        use.createEvent();
        use.activeIndex();
      }, 100);
    });

    return { ...use };
  }
});
</script>

<style>
.v-menu-pos {
  width: 200px;
  position: fixed;
  background-color: #032c41;
  border-radius: 10px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.12), 0 0 6px rgba(0, 0, 0, 0.04);
}
.v-navigation {
  height: 100%;
  background-color: #032c41;
}
.v-menu-wrapper {
  background-color: #eee;
  text-align: center;
  padding: 5px 0;
  cursor: pointer;
  transition: background-color 0.25s ease-out;
}
.v-menu-wrapper > .icon {
  margin-right: 0px !important;
}
.v-menu-wrapper:hover {
  background-color: #ccc;
}

.icon-small {
  width: 0.8em;
  height: 0.8em;
}

.box {
  width: 100%;
  position: relative;
  color: #eee;
  cursor: pointer;
  padding: 15px 0;
  overflow: hidden;
  transition: all 0.25s ease;
  background-color: #032c41;
}

.v-menu-pos-item {
  position: relative;
}

.v-menu-pos-item > .move {
  border: none !important;
}

.v-menu-pos-item:hover > .move {
  width: 100% !important;
}
.box:hover > .move {
  width: 100% !important;
  border-left: 2px solid #fff !important;
}

.active-move {
  width: 100% !important;
  border-left: 2px solid #fff !important;
}

.move {
  position: absolute;
  left: 0;
  top: 0;
  width: 0;
  height: 50px;
  background-image: linear-gradient(
    to right,
    rgb(255, 255, 255, 0.1),
    rgb(255, 255, 255, 0)
  );
  transition: width 0.25s ease;
}

.wrapper {
  width: v-bind(_sideWidth);
  background-color: #032c41;
  user-select: none;
  overflow: auto;
  font-size: 14px;
  transition: width 0.25s ease-out;
}

.wrapper::-webkit-scrollbar {
  width: 10px;
  border-radius: 40px;
  background-color: #032c41;
}
.wrapper::-webkit-scrollbar-thumb {
  width: 5px;
  border-radius: 40px;
  background-color: #02273a;
}
.wrapper::-webkit-scrollbar-button {
  display: none;
}

.item-list {
  width: 100%;
  height: 0px;
  overflow: hidden;
  transition: all 0.25s ease-in-out;
  font-size: inherit;
}

.item-list > .box {
  background-color: #02273a;
  font-size: inherit;
}

.item {
  padding: 0 20px;
  font-size: inherit;
}

.show {
  height: auto !important;
  max-height: 9999px !important;
}
</style>
